/*
 * @lc app=leetcode.cn id=482 lang=javascript
 *
 * [482] 密钥格式化
 */

// @lc code=start
/**
 * @param {string} s
 * @param {number} k
 * @return {string}
 */
var licenseKeyFormatting = function(s, k) {
    s = s.toLocaleUpperCase().replaceAll('-', '')
    let result = ''
    for (let index = 0; index < s.length; index++) {
        let e = s[s.length - 1 - index];
        if ((index + 1) % k === 0 && index !== s.length - 1) {
            e = '-' + e
        }
        result = e + result
    }
    return result
};
// @lc code=end

